package easy;
//找出最大连续子串长度

public class test35 {
    public static void main(String[] args) {
        System.out.println(maxPower("leetcode"));
        System.out.println(maxPower2("abbcccddddeeeeedcba"));
    }

    public static int maxPower(String s) {
        int l = 0, a = 1, max = 0;
        if (s.length() == 1) {
            return 1;
        }
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(l) == s.charAt(i)) {
                a++;
            } else {
                l = i;
                a = 1;
            }
            max = Math.max(a, max);
        }
        return max;
    }

    public static int maxPower2(String s) {
        int n = s.length(), ans = 1;
        for (int i = 0; i < n; ) {
            int j = i;
            while (j < n && s.charAt(j) == s.charAt(i)) j++;
            ans = Math.max(ans, j - i);
            i = j;

        }
        return ans;
    }

}
